package com.hf.hfp.service.impl;

import com.hf.hfp.dao.AdminDao;
import com.hf.hfp.entity.Admin;
import com.hf.hfp.service.intf.AdminService;
import com.hf.hfp.util.RUtil;
import com.hf.hfp.vo.PageBean;
import com.hf.hfp.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.List;

/**
 * @author zhoujingluo
 * @date 2021/6/16 14:19
 */
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminDao adminDao;

    @Override
    public R save(Admin admin) {
        if(admin != null && admin.getName() != null){
            //密码 加密
            admin.setPassword(DigestUtils.md5DigestAsHex(admin.getPassword().getBytes()));
            if(adminDao.insert(admin)>0){
                //新增成功
                return RUtil.ok();
            }
        }
        return RUtil.fail();
    }

    @Override
    public PageBean queryList() {
        List<Admin> list=adminDao.selectAll();
        return new PageBean(0,"",list.size(),list);
    }
}
